/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Formularios;

import BD.Validacao;
import BD.pizzas;
import BD.sabores;
import BD.utilsPim;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author CORE
 */
public class FormPizzas extends javax.swing.JFrame {

    public String Tipo = "";
    pizzas pizza = new pizzas();
    sabores sabor = new sabores();
    ArrayList<pizzas> listPizzas = new ArrayList<pizzas>();    
    utilsPim utlp = new utilsPim();    

    int ponteiro       = 0;
    boolean Incluindo  = false;
    Validacao vldc = new Validacao();

    /**
     * Creates new form FormPizzas
     */
    public FormPizzas() {
        initComponents();
        TravaBtns(false, true, false);
        CarregaCombobox();
        setLocationRelativeTo(null);
        limpaCampo();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpnlPesq = new javax.swing.JPanel();
        jbtnPesquisa = new javax.swing.JButton();
        jpNavegacao = new javax.swing.JPanel();
        jbtnFirst = new javax.swing.JButton();
        jbtnPrior = new javax.swing.JButton();
        jbtnNext = new javax.swing.JButton();
        jbtnLast = new javax.swing.JButton();
        jcbxsaborPesq = new javax.swing.JComboBox();
        labelProdutos1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jcbxsabor = new javax.swing.JComboBox();
        labelProdutos = new javax.swing.JLabel();
        jtcodigo = new javax.swing.JTextField();
        labelCodigo = new javax.swing.JLabel();
        jtValorUN = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jbtnNovo = new javax.swing.JButton();
        jbtnAlterar = new javax.swing.JButton();
        jbtnGravar = new javax.swing.JButton();
        jbtnexcluir = new javax.swing.JButton();
        jbtncancelar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jcbxTamanho = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Master Pizza - Cadastro de Pizzas");

        jpnlPesq.setBorder(javax.swing.BorderFactory.createCompoundBorder());

        jbtnPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Pesquisa.png"))); // NOI18N
        jbtnPesquisa.setText("Pesquisar");
        jbtnPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPesquisaActionPerformed(evt);
            }
        });

        jbtnFirst.setText("<<");
        jbtnFirst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnFirstActionPerformed(evt);
            }
        });

        jbtnPrior.setText("<");
        jbtnPrior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPriorActionPerformed(evt);
            }
        });

        jbtnNext.setText(">");
        jbtnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNextActionPerformed(evt);
            }
        });

        jbtnLast.setText(">>");
        jbtnLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnLastActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpNavegacaoLayout = new javax.swing.GroupLayout(jpNavegacao);
        jpNavegacao.setLayout(jpNavegacaoLayout);
        jpNavegacaoLayout.setHorizontalGroup(
            jpNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNavegacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnPrior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnLast)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpNavegacaoLayout.setVerticalGroup(
            jpNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpNavegacaoLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jpNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnFirst)
                    .addComponent(jbtnPrior)
                    .addComponent(jbtnNext)
                    .addComponent(jbtnLast)))
        );

        jcbxsaborPesq.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        labelProdutos1.setText("Sabor");

        javax.swing.GroupLayout jpnlPesqLayout = new javax.swing.GroupLayout(jpnlPesq);
        jpnlPesq.setLayout(jpnlPesqLayout);
        jpnlPesqLayout.setHorizontalGroup(
            jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlPesqLayout.createSequentialGroup()
                .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlPesqLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labelProdutos1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbxsaborPesq, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnPesquisa))
                    .addGroup(jpnlPesqLayout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(jpNavegacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(jSeparator1)
        );
        jpnlPesqLayout.setVerticalGroup(
            jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlPesqLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnPesquisa)
                    .addComponent(jcbxsaborPesq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelProdutos1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpNavegacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jcbxsabor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        labelProdutos.setText("Sabor");

        labelCodigo.setText("Código");

        jtValorUN.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtValorUNKeyTyped(evt);
            }
        });

        jLabel4.setText("Valor Unitário");

        jbtnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Incluir.png"))); // NOI18N
        jbtnNovo.setText("Novo");
        jbtnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNovoActionPerformed(evt);
            }
        });

        jbtnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Alterar.png"))); // NOI18N
        jbtnAlterar.setText("Alterar");
        jbtnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAlterarActionPerformed(evt);
            }
        });

        jbtnGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Gravar.png"))); // NOI18N
        jbtnGravar.setText("Gravar");
        jbtnGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnGravarActionPerformed(evt);
            }
        });

        jbtnexcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Excluir.png"))); // NOI18N
        jbtnexcluir.setText("Excluir");
        jbtnexcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnexcluirActionPerformed(evt);
            }
        });

        jbtncancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Cancelar.png"))); // NOI18N
        jbtncancelar.setText("Cancelar");
        jbtncancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtncancelarActionPerformed(evt);
            }
        });

        jLabel2.setText("Tamanho");

        jcbxTamanho.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "P", "M", "G" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpnlPesq, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jSeparator2)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelCodigo)
                                    .addComponent(jtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelProdutos)
                                    .addComponent(jcbxsabor, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(18, 18, 18))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jcbxTamanho, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(10, 10, 10)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtValorUN, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4)))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtnNovo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnAlterar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnGravar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnexcluir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtncancelar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpnlPesq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(labelCodigo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(labelProdutos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbxsabor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtValorUN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcbxTamanho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel4))
                .addGap(24, 24, 24)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtncancelar)
                    .addComponent(jbtnexcluir)
                    .addComponent(jbtnGravar)
                    .addComponent(jbtnAlterar)
                    .addComponent(jbtnNovo))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CarregaCombobox() {
        sabores sab = new sabores();        
        jcbxsabor.removeAllItems();
        jcbxsaborPesq.removeAllItems();
        jcbxTamanho.removeAllItems();

        ArrayList<sabores> listsa = new ArrayList<sabores>() ;
        listsa = sab.getItens();
        
        for (int i = 0; i < listsa.size(); i++) {
            jcbxsabor.addItem(listsa.get(i).getDescricao());
            jcbxsaborPesq.addItem(listsa.get(i).getDescricao());

        }
        jcbxTamanho.addItem("P");
        jcbxTamanho.addItem("M");
        jcbxTamanho.addItem("G");
        
        jcbxTamanho.setSelectedIndex(-1);
        jcbxsabor.setSelectedIndex(-1);
        jcbxsaborPesq.setSelectedIndex(-1);       
    }
    private void limpaCampo() {
        this.jtcodigo.setText("");
        this.jcbxTamanho.setSelectedIndex(-1);
        this.jtValorUN.setText("");
        this.jcbxsabor.setSelectedIndex(-1);
        
    }
    private boolean Validacao() {       
//        return (vldc.Valida(String.valueOf(jcbxproduto.getSelectedItem()), "Produto"));
//        return (vldc.Valida(jcbxproduto.getSelectedItem(), "Produto"));
        String   s = "";
        if( jcbxsabor.getSelectedIndex()< 0)        
         s = "";
        else
         s =(String) jcbxsabor.getSelectedItem();
        return (vldc.Valida(s, "Sabor")&& vldc.Valida(jcbxTamanho.getSelectedIndex()+1, "Tamanho") 
                && vldc.Valida(jtValorUN.getText(), "Valor"));
    }
    

    private void TravaBtns(boolean incluindo, boolean navegando, boolean pesquisando) {
        jtcodigo.setEditable(false);
        
        //jcbxTamanho.setEnabled(incluindo);
        jtValorUN.setEditable(incluindo);
        jpNavegacao.setVisible(!incluindo);
        

        if (incluindo) {
            jbtncancelar.setVisible(true);
            jbtnGravar.setVisible(true);
            jpnlPesq.setVisible(false);
            jbtnexcluir.setVisible(false);
            jbtnNovo.setVisible(false);
            jbtnAlterar.setVisible(false);
        } else if (navegando) {
            jbtnAlterar.setVisible(true);
            jbtncancelar.setVisible(false);
            jbtnGravar.setVisible(false);
            jpnlPesq.setVisible(true);
            jbtnexcluir.setVisible(true);
            jbtnNovo.setVisible(true);
        }

        //jbtnPesquiza.enable(pTipo);
    }
    
    private void movPonteiro(boolean first, boolean prior, boolean next, boolean last) {
        if (listPizzas.size() > 0) {
            if (first) {
                this.ponteiro = 0;
            } else if (prior) {
                this.ponteiro = this.ponteiro - 1;
                if (this.ponteiro < 0) {
                    this.ponteiro = 0;
                }
            } else if (next) {
                this.ponteiro = this.ponteiro + 1;
                if (this.ponteiro > (listPizzas.size() - 1)) {
                    this.ponteiro = (listPizzas.size() - 1);
                }
            } else if (last) {
                this.ponteiro = (listPizzas.size() - 1);
            }
            
            this.jtcodigo.setText(Integer.toString(listPizzas.get(this.ponteiro).getId_pizzas()));
            this.jcbxTamanho.removeAllItems();
            this.jcbxTamanho.addItem(listPizzas.get(this.ponteiro).getTamanho());            
            this.jcbxTamanho.setSelectedIndex(0);
            //this.jcbxTamanho.setSelectedIndex(utlp.getIndexCombobox(jcbxTamanho, listPizzas.get(this.ponteiro).getTamanho()  ));
            //this.jtTamanho.setText(listPizzas.get(this.ponteiro).getTamanho());            
            this.jtValorUN.setText(utlp.formatavalor(listPizzas.get(this.ponteiro).getValor()));
            
            this.jcbxsabor.removeAllItems();
            this.jcbxsabor.addItem(listPizzas.get(this.ponteiro).getDesc_sabor());
            this.jcbxsabor.setSelectedIndex(0);

        } else {
            limpaCampo();
        }
    }
    
    private void jbtnPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPesquisaActionPerformed
        if(jcbxsaborPesq.getSelectedIndex()>=0)
        pizza.setDesc_sabor(jcbxsaborPesq.getSelectedItem().toString());
        if(jcbxsaborPesq.getSelectedIndex() == -1)
            pizza.setDesc_sabor("");
            
        listPizzas = pizza.getItens();         // TODO add your handling code here:
        TravaBtns(false, true, true);
        jbtnFirstActionPerformed(evt);
    }//GEN-LAST:event_jbtnPesquisaActionPerformed

    private void jbtnFirstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnFirstActionPerformed
        movPonteiro(true, false, false, false);
    }//GEN-LAST:event_jbtnFirstActionPerformed

    private void jbtnPriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPriorActionPerformed
        movPonteiro(false, true, false, false);
    }//GEN-LAST:event_jbtnPriorActionPerformed

    private void jbtnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNextActionPerformed
        movPonteiro(false, false, true, false);
    }//GEN-LAST:event_jbtnNextActionPerformed

    private void jbtnLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnLastActionPerformed
        movPonteiro(false, false, false, true);
    }//GEN-LAST:event_jbtnLastActionPerformed

    private void jbtnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNovoActionPerformed

        Incluindo = true;
        TravaBtns(true, false, false);
        limpaCampo();
        CarregaCombobox();
    }//GEN-LAST:event_jbtnNovoActionPerformed

    private void jbtnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAlterarActionPerformed
        if (listPizzas.size() > 0) {
            TravaBtns(true, false, false);
            Incluindo = false;
            //preenche od valores atuais no combobox
            String  Strpro =(String) jcbxsabor.getSelectedItem();
            String s = jcbxTamanho.getSelectedItem().toString();
            CarregaCombobox();
            //reposiciona o combobox no registro que vai ser alterado
            utlp.getIndexComboboxSet(jcbxsabor,Strpro);
            utlp.getIndexComboboxSet(jcbxTamanho,s);
            jtValorUN.setText(jtValorUN.getText().replace("R$ ", ""));
        } else {
            JOptionPane.showMessageDialog(null, "Nenhum registro Encontrado");
        }
    }//GEN-LAST:event_jbtnAlterarActionPerformed

    private void jbtnGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnGravarActionPerformed
        if (Validacao()) {
            pizzas pizza = new pizzas();
            sabores sab = new sabores();
            
            sab.setDescricao((String) this.jcbxsabor.getSelectedItem());
            ArrayList<sabores> lsab = new ArrayList<sabores>();
            lsab = sab.getItens();
            
            
            pizza.setId_sabores(lsab.get(0).getId_sabores());
            pizza.setTamanho(jcbxTamanho.getSelectedItem().toString());
//            pizza.setValor(Float.parseFloat( utlp.formatavalorsemmaskS( jtValorUN.getText() )) );
            pizza.setValor(Float.parseFloat( jtValorUN.getText().replace(",",".")));


            //pósiciona o cbx codigo para pegar os id's

            if (Incluindo) {
                if (pizza.incluir()) {
                    TravaBtns(false, true, false);
                    jcbxsaborPesq.removeAll();
                    jcbxsaborPesq.addItem(lsab.get(0).getDescricao());
                    jbtnPesquisaActionPerformed(evt);
                    CarregaCombobox();
                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao incluir Compras");
                }
            } else {
                pizza.setId_pizzas(Integer.parseInt(this.jtcodigo.getText()));
                if (pizza.alterar()) {

                    jbtnPesquisaActionPerformed(evt);

                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao alterar Compras");
                }
            }

        }
    }//GEN-LAST:event_jbtnGravarActionPerformed

    private void jbtnexcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnexcluirActionPerformed

        if (listPizzas.size() <= 0) {
            JOptionPane.showMessageDialog(null, "Nenhum registro Encontrado");
        } else {
            if (JOptionPane.showConfirmDialog(null, "Deseja exluir a pizza sabor:" +
                listPizzas.get(ponteiro).getDesc_sabor()+
                " Do tamanho: "+listPizzas.get(ponteiro).getTamanho()
            ) == 0)
            {
                if (listPizzas.get(ponteiro).excluir()) {
                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                    limpaCampo();
                    jbtnPesquisaActionPerformed(evt);
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao excluir o registro");
                }
            }
        }
    }//GEN-LAST:event_jbtnexcluirActionPerformed

    private void jbtncancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtncancelarActionPerformed
        // TODO add your handling code here:
        Incluindo = false;
        TravaBtns(false, true, false);
        limpaCampo();
    }//GEN-LAST:event_jbtncancelarActionPerformed

    private void jtValorUNKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtValorUNKeyTyped
        String caracteres = "0987654321.";
        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_jtValorUNKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormPizzas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormPizzas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormPizzas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormPizzas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormPizzas().setVisible(true);
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JButton jbtnAlterar;
    private javax.swing.JButton jbtnFirst;
    private javax.swing.JButton jbtnGravar;
    private javax.swing.JButton jbtnLast;
    private javax.swing.JButton jbtnNext;
    private javax.swing.JButton jbtnNovo;
    private javax.swing.JButton jbtnPesquisa;
    private javax.swing.JButton jbtnPrior;
    private javax.swing.JButton jbtncancelar;
    private javax.swing.JButton jbtnexcluir;
    private javax.swing.JComboBox jcbxTamanho;
    private javax.swing.JComboBox jcbxsabor;
    private javax.swing.JComboBox jcbxsaborPesq;
    private javax.swing.JPanel jpNavegacao;
    private javax.swing.JPanel jpnlPesq;
    private javax.swing.JTextField jtValorUN;
    private javax.swing.JTextField jtcodigo;
    private javax.swing.JLabel labelCodigo;
    private javax.swing.JLabel labelProdutos;
    private javax.swing.JLabel labelProdutos1;
    // End of variables declaration//GEN-END:variables
}
